package com.chris.homecare.screens
{
	import com.chris.homecare.components.BreadcrumbComponenet;
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.components.renderers.ServicesListRenderer;
	import com.chris.homecare.data.FetchRemoteData;
	import com.chris.homecare.utils.CommonUtils;
	
	import feathers.controls.Label;
	import feathers.controls.List;
	import feathers.controls.Screen;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.layout.VerticalLayout;
	
	import starling.display.Quad;
	import starling.events.Event;

	public class PatientListScreen extends Screen
	{
		private var headerComp:HeaderComponent;
		private var patientList:List;

		//private var infoLabel:Label;
		private var breadcrumbComp:BreadcrumbComponenet;
		
		public function PatientListScreen()
		{
			
		}
		
		override protected function initialize():void
		{
			this.layout = new VerticalLayout();
			
			headerComp = new HeaderComponent();
			addChild(headerComp);
			
			breadcrumbComp = new BreadcrumbComponenet("Choose your patient");
			addChild(breadcrumbComp);
			/*infoLabel = new Label();
			infoLabel.text = "  Choose your patient...";
			addChild(infoLabel);*/
			
			var gapingQuad:Quad = new Quad(2,10,0xFFFFFF);
			addChild(gapingQuad);
			
			
			patientList = new List();
			patientList.itemRendererFactory = function ():IListItemRenderer
			{
				var renderer:ServicesListRenderer = new ServicesListRenderer();
				return renderer;
			};
			/*patientList.dataProvider = new ListCollection([{header:"Elen", address:"15 Balfour Road, IG1 4HP, Ilford, Greater London, United Kingdom"}, 
				{header:"Paul", address:"IG1 1TG, Ilford, Greater London, England, United Kingdom"}, 
				{header:"Adam", address:"74 Westbury Road, IG1 3BW, Ilford, Greater London, United Kingdom"}, 
				{header:"Oliver", address:"71 York Road, Ilford, Greater London, England, United Kingdom"}]);*/
			patientList.dataProvider = CommonUtils.patientListCollection;
			patientList.addEventListener(Event.CHANGE, onEmployeeVauleChanged);
			addChild(patientList);
			patientList.backgroundSkin = new Quad(10,10,0xFFFFFF);
			patientList.backgroundDisabledSkin = new Quad(10,10,0xFFFFFF);
			
			super.initialize();
		}
		
		override protected function draw():void
		{
			patientList.width = this.width;
			patientList.height = stage.stageHeight - headerComp.height - breadcrumbComp.height - 10;
			super.draw();
		}
		
		private function onEmployeeVauleChanged():void
		{
			if(patientList.selectedItem)
			{
				FetchRemoteData.choosenPatient = patientList.selectedItem;
				this.dispatchEventWith(Event.CHANGE);
			}
		}
	}
}